﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace RandomGenerator
{
    class LevelGenerator
    {

        public void CreateLevels(int Level, string GameType)
        {
            switch (GameType)
            {
                // Each round continues from the round before it
                case "Continuous":
                    ContSequence(Level);
                    break;
                // Each round is longer but a completely new sequence
                case "Random":
                    RandSequence(Level);
                    break;
            }
        }
        public void ContSequence(int Level)
        {
            /*
             * Run a nested loop to convert the sequence to xml elements
             * Write to file
             */
            List<string> FullList = GenList(Level);
            // Create xml main list
            XmlDocument LevelsXml = new XmlDocument();
            XmlElement rootElem = LevelsXml.CreateElement("Levels");
            LevelsXml.AppendChild(rootElem);

            for (int i = 0; i < Level; i++)
            {
                // Create xml headers
                string lvlText = "Level " + i;
                XmlElement curLevel = LevelsXml.CreateElement("Level");
                for (int n = 0; n <= i; n++)
                {
                    // Create xml elements
                    XmlElement step = LevelsXml.CreateElement(FullList[n]);
                    //Console.WriteLine(FullList[n]);
                }
            }
            //Console.WriteLine(LevelsXml.OuterXml);
            //Console.Read();
        }

        public void RandSequence(int Level)
        {
            /*
             * Run a loop to get multiple sets of numbers
             * Convert each to xml elements
             * Write file
             */
            
            // Create xml main list
            for (int i = 0; i < Level; i++)
            {
                // Create xml headers
                List<string> FullList = GenList(Level);
                // Create xml elements
            }
        }

        public List<string> GenList(int Level)
        {
            // Get a set of colors and place them in a list
            List<string> Sequence = new List<string>();
            for (int i = 0; i < Level; i++)
            {
                Sequence.Add(GetRandColor());
                System.Threading.Thread.Sleep(10);
            }
            return Sequence;
        }


        public string GetRandColor()
        {
            Random Rnd = new Random();
            string sndColor = "";
            int RndNum = Rnd.Next(0, 4);  // Rand 0-3
            // Convert numbers to color strings
            switch (RndNum)
            {
                case 0:
                    sndColor = "Blue";
                    break;
                case 1:
                    sndColor = "Yellow";
                    break;
                case 2:
                    sndColor = "Green";
                    break;
                case 3:
                    sndColor = "Red";
                    break;
            }
            return sndColor;
        }
    }
}
